package feiyanren.com;

public class A03_Demo3 {
    public static void main(String[] args) {
        int[] arr = {27,22,40,36,12,14,52,73,60,89,90,100};
        Blocks block1 = new Blocks(12,40,0,5);
        Blocks block2 = new Blocks(52,100,6,11);
        Blocks[] blocks = {block1,block2};
        Blocks targetBlock = findBlock(89,blocks);
        System.out.println(findIndex(arr,targetBlock,89));
    }
    public static Blocks findBlock(int number,Blocks[] blocks){
        for(int i=0;i<blocks.length;i++){
            if(number >= blocks[i].getMin() && number <= blocks[i].getMax()){
                return blocks[i];
            }
        }
        return null;
    }
    public static int findIndex(int[] arr,Blocks block,int target){
        if(block == null){
            return -1;
        }
        for(int i=block.getStartIndex();i<=block.getEndIndex();i++){
            if(target == arr[i]){
                return i;
            }
        }
        return -1;
    }
}
class Blocks{
    private int min;
    private int max;
    private int startIndex;
    private int endIndex;

    public Blocks(int min, int max, int startIndex, int endIndex) {
        this.min = min;
        this.max = max;
        this.startIndex = startIndex;
        this.endIndex = endIndex;
    }

    public Blocks() {
    }

    public int getMin() {
        return min;
    }

    public void setMin(int min) {
        this.min = min;
    }

    public int getMax() {
        return max;
    }

    public void setMax(int max) {
        this.max = max;
    }

    public int getStartIndex() {
        return startIndex;
    }

    public void setStartIndex(int startIndex) {
        this.startIndex = startIndex;
    }

    public int getEndIndex() {
        return endIndex;
    }

    public void setEndIndex(int endIndex) {
        this.endIndex = endIndex;
    }
}